﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.LoadedPmiTypes.CUiLoadedPmiTypesForm
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using C1.Win.C1FlexGrid;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;
using Tecnomatix.Engineering.Ui48;


namespace DnProcessSimulateCommands.LoadedPmiTypes;

public class CUiLoadedPmiTypesForm : TxForm
{
  private List<TxPmiType> m_excludedTypes;
  private IContainer components;
  private Button m_buttonAdd;
  private Button m_buttonRemoveAll;
  private Button m_buttonAddAll;
  private Button m_buttonRemove;
  private Label label1;
  private Label label2;
  private Button m_buttonOK;
  private Button m_buttonCancel;
  private ImageList m_imageList;
  private CUiLoadedPmiTypesFlexGrid m_flexGridIncludedTypes;
  private CUiLoadedPmiTypesFlexGrid m_flexGridExcludedTypes;

  public CUiLoadedPmiTypesForm(List<TxPmiType> excludedTypes)
  {
    this.m_excludedTypes = excludedTypes;
    this.InitializeComponent();
  }

  public List<TxPmiType> ExcludedTypes
  {
    get => this.m_excludedTypes;
    private set => this.m_excludedTypes = value;
  }

  private void TxLoadedPmiTypesForm_Load(object sender, EventArgs e)
  {
    this.m_flexGridIncludedTypes.Init((TxFlexGrid) this.m_flexGridExcludedTypes);
    this.m_flexGridExcludedTypes.Init((TxFlexGrid) this.m_flexGridIncludedTypes);
    this.m_flexGridIncludedTypes.LoadAllPmiTypes();
    foreach (TxPmiType excludedType in this.m_excludedTypes)
    {
      foreach (Node nodes in this.m_flexGridIncludedTypes.NodesList())
      {
        if (TxPmiType.op_Equality(excludedType, nodes.PmiType()))
          nodes.MoveToOppositeGrid();
      }
    }
    this.UpdateButtons();
  }

  private void m_buttonAdd_Click(object sender, EventArgs e)
  {
    this.m_flexGridIncludedTypes.MoveSelectedNodes();
    this.UpdateButtons();
  }

  private void m_buttonRemove_Click(object sender, EventArgs e)
  {
    this.m_flexGridExcludedTypes.MoveSelectedNodes();
    this.UpdateButtons();
  }

  private void m_buttonAddAll_Click(object sender, EventArgs e)
  {
    this.m_flexGridExcludedTypes.LoadAllPmiTypes();
    this.UpdateButtons();
  }

  private void m_buttonRemoveAll_Click(object sender, EventArgs e)
  {
    this.m_flexGridIncludedTypes.LoadAllPmiTypes();
    this.UpdateButtons();
  }

  private void m_buttonOK_Click(object sender, EventArgs e)
  {
    this.ExcludedTypes = this.GetExcludedPmiTypes();
    ((Form) this).Close();
  }

  private List<TxPmiType> GetExcludedPmiTypes()
  {
    List<TxPmiType> excludedPmiTypes = new List<TxPmiType>();
    foreach (Node nodes in this.m_flexGridExcludedTypes.NodesList())
    {
      int length = nodes.Nodes.Length;
      TxPmiType txPmiType = nodes.PmiType();
      int count = ((TxPmiType) ref txPmiType).GetDerivedTypes().Count;
      if (length != count)
      {
        foreach (Node node in nodes.Nodes)
          excludedPmiTypes.Add(node.PmiType());
      }
      else if (nodes.Level == 0)
        excludedPmiTypes.Add(nodes.PmiType());
    }
    return excludedPmiTypes;
  }

  private void UpdateButtons()
  {
    this.m_buttonAdd.Enabled = this.m_flexGridIncludedTypes.HasSelection();
    this.m_buttonRemove.Enabled = this.m_flexGridExcludedTypes.HasSelection();
  }

  private void FlexGrid_KeyDown(object sender, KeyEventArgs e)
  {
    CUiLoadedPmiTypesFlexGrid pmiTypesFlexGrid = sender as CUiLoadedPmiTypesFlexGrid;
    if (!e.Control || e.KeyCode != Keys.A)
      return;
    foreach (Node nodes in pmiTypesFlexGrid.NodesList())
      ((RowCol) nodes.Row).Selected = true;
  }

  private void FlexGrid_SelChange(object sender, EventArgs e) => this.UpdateButtons();

  private void CUiLoadedPmiTypesForm_SizeChanged(object sender, EventArgs e)
  {
    int num1 = 6;
    int num2 = (((Form) this).ClientSize.Width - 2 * ((Control) this.m_flexGridIncludedTypes).Left - this.m_buttonAdd.Width - 2 * num1) / 2;
    ((Control) this.m_flexGridIncludedTypes).Width = num2;
    this.m_buttonAdd.Left = ((Control) this.m_flexGridIncludedTypes).Right + num1;
    this.m_buttonAddAll.Left = this.m_buttonAdd.Left;
    this.m_buttonRemove.Left = this.m_buttonAdd.Left;
    this.m_buttonRemoveAll.Left = this.m_buttonAdd.Left;
    ((Control) this.m_flexGridExcludedTypes).Left = ((Control) this.m_flexGridIncludedTypes).Left + num2 + this.m_buttonAdd.Width + 2 * num1;
    ((Control) this.m_flexGridExcludedTypes).Width = num2;
    this.label2.Left = ((Control) this.m_flexGridExcludedTypes).Left;
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    this.components = (IContainer) new Container();
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiLoadedPmiTypesForm));
    this.m_imageList = new ImageList(this.components);
    this.m_buttonAdd = new Button();
    this.m_buttonRemoveAll = new Button();
    this.m_buttonAddAll = new Button();
    this.m_buttonRemove = new Button();
    this.label1 = new Label();
    this.label2 = new Label();
    this.m_buttonOK = new Button();
    this.m_buttonCancel = new Button();
    this.m_flexGridExcludedTypes = new CUiLoadedPmiTypesFlexGrid();
    this.m_flexGridIncludedTypes = new CUiLoadedPmiTypesFlexGrid();
    ((ISupportInitialize) this.m_flexGridExcludedTypes).BeginInit();
    ((ISupportInitialize) this.m_flexGridIncludedTypes).BeginInit();
    ((Control) this).SuspendLayout();
    this.m_imageList.ColorDepth = ColorDepth.Depth8Bit;
    componentResourceManager.ApplyResources((object) this.m_imageList, "m_imageList");
    this.m_imageList.TransparentColor = Color.Transparent;
    componentResourceManager.ApplyResources((object) this.m_buttonAdd, "m_buttonAdd");
    this.m_buttonAdd.Name = "m_buttonAdd";
    this.m_buttonAdd.UseVisualStyleBackColor = true;
    this.m_buttonAdd.Click += new EventHandler(this.m_buttonAdd_Click);
    componentResourceManager.ApplyResources((object) this.m_buttonRemoveAll, "m_buttonRemoveAll");
    this.m_buttonRemoveAll.Name = "m_buttonRemoveAll";
    this.m_buttonRemoveAll.UseVisualStyleBackColor = true;
    this.m_buttonRemoveAll.Click += new EventHandler(this.m_buttonRemoveAll_Click);
    componentResourceManager.ApplyResources((object) this.m_buttonAddAll, "m_buttonAddAll");
    this.m_buttonAddAll.Name = "m_buttonAddAll";
    this.m_buttonAddAll.UseVisualStyleBackColor = true;
    this.m_buttonAddAll.Click += new EventHandler(this.m_buttonAddAll_Click);
    componentResourceManager.ApplyResources((object) this.m_buttonRemove, "m_buttonRemove");
    this.m_buttonRemove.Name = "m_buttonRemove";
    this.m_buttonRemove.UseVisualStyleBackColor = true;
    this.m_buttonRemove.Click += new EventHandler(this.m_buttonRemove_Click);
    componentResourceManager.ApplyResources((object) this.label1, "label1");
    this.label1.Name = "label1";
    componentResourceManager.ApplyResources((object) this.label2, "label2");
    this.label2.Name = "label2";
    componentResourceManager.ApplyResources((object) this.m_buttonOK, "m_buttonOK");
    this.m_buttonOK.DialogResult = DialogResult.OK;
    this.m_buttonOK.Name = "m_buttonOK";
    this.m_buttonOK.UseVisualStyleBackColor = true;
    this.m_buttonOK.Click += new EventHandler(this.m_buttonOK_Click);
    componentResourceManager.ApplyResources((object) this.m_buttonCancel, "m_buttonCancel");
    this.m_buttonCancel.DialogResult = DialogResult.Cancel;
    this.m_buttonCancel.Name = "m_buttonCancel";
    this.m_buttonCancel.UseVisualStyleBackColor = true;
    ((C1FlexGridBase) this.m_flexGridExcludedTypes).AllowDragging = (AllowDraggingEnum) 0;
    ((C1FlexGridBase) this.m_flexGridExcludedTypes).AllowEditing = false;
    componentResourceManager.ApplyResources((object) this.m_flexGridExcludedTypes, "m_flexGridExcludedTypes");
    ((C1FlexGridBase) this.m_flexGridExcludedTypes).ExtendLastCol = true;
    ((C1FlexGridBase) this.m_flexGridExcludedTypes).FocusRect = (FocusRectEnum) 0;
    ((Control) this.m_flexGridExcludedTypes).Name = "m_flexGridExcludedTypes";
    ((RowColCollection) ((C1FlexGridBase) this.m_flexGridExcludedTypes).Rows).Count = 0;
    ((RowColCollection) ((C1FlexGridBase) this.m_flexGridExcludedTypes).Rows).Fixed = 0;
    ((C1FlexGridBase) this.m_flexGridExcludedTypes).SelectionMode = (SelectionModeEnum) 7;
    ((C1FlexGridBase) this.m_flexGridExcludedTypes).StyleInfo = componentResourceManager.GetString("m_flexGridExcludedTypes.StyleInfo");
    ((C1FlexGridBase) this.m_flexGridExcludedTypes).Tree.Column = 0;
    ((C1FlexGridBase) this.m_flexGridExcludedTypes).SelChange += new EventHandler(this.FlexGrid_SelChange);
    ((Control) this.m_flexGridExcludedTypes).KeyDown += new KeyEventHandler(this.FlexGrid_KeyDown);
    ((C1FlexGridBase) this.m_flexGridIncludedTypes).AllowDragging = (AllowDraggingEnum) 0;
    ((C1FlexGridBase) this.m_flexGridIncludedTypes).AllowEditing = false;
    componentResourceManager.ApplyResources((object) this.m_flexGridIncludedTypes, "m_flexGridIncludedTypes");
    ((C1FlexGridBase) this.m_flexGridIncludedTypes).ExtendLastCol = true;
    ((C1FlexGridBase) this.m_flexGridIncludedTypes).FocusRect = (FocusRectEnum) 0;
    ((Control) this.m_flexGridIncludedTypes).Name = "m_flexGridIncludedTypes";
    ((RowColCollection) ((C1FlexGridBase) this.m_flexGridIncludedTypes).Rows).Count = 0;
    ((RowColCollection) ((C1FlexGridBase) this.m_flexGridIncludedTypes).Rows).Fixed = 0;
    ((C1FlexGridBase) this.m_flexGridIncludedTypes).SelectionMode = (SelectionModeEnum) 7;
    ((C1FlexGridBase) this.m_flexGridIncludedTypes).StyleInfo = componentResourceManager.GetString("m_flexGridIncludedTypes.StyleInfo");
    ((C1FlexGridBase) this.m_flexGridIncludedTypes).Tree.Column = 0;
    ((C1FlexGridBase) this.m_flexGridIncludedTypes).SelChange += new EventHandler(this.FlexGrid_SelChange);
    ((Control) this.m_flexGridIncludedTypes).KeyDown += new KeyEventHandler(this.FlexGrid_KeyDown);
    ((Form) this).AcceptButton = (IButtonControl) this.m_buttonOK;
    componentResourceManager.ApplyResources((object) this, "$this");
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Form) this).CancelButton = (IButtonControl) this.m_buttonCancel;
    ((Control) this).Controls.Add((Control) this.m_flexGridExcludedTypes);
    ((Control) this).Controls.Add((Control) this.m_flexGridIncludedTypes);
    ((Control) this).Controls.Add((Control) this.m_buttonCancel);
    ((Control) this).Controls.Add((Control) this.m_buttonOK);
    ((Control) this).Controls.Add((Control) this.label2);
    ((Control) this).Controls.Add((Control) this.label1);
    ((Control) this).Controls.Add((Control) this.m_buttonRemove);
    ((Control) this).Controls.Add((Control) this.m_buttonAddAll);
    ((Control) this).Controls.Add((Control) this.m_buttonRemoveAll);
    ((Control) this).Controls.Add((Control) this.m_buttonAdd);
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CUiLoadedPmiTypesForm);
    ((Form) this).ShowIcon = false;
    ((Form) this).SizeGripStyle = SizeGripStyle.Hide;
    ((Form) this).Load += new EventHandler(this.TxLoadedPmiTypesForm_Load);
    ((Control) this).SizeChanged += new EventHandler(this.CUiLoadedPmiTypesForm_SizeChanged);
    ((ISupportInitialize) this.m_flexGridExcludedTypes).EndInit();
    ((ISupportInitialize) this.m_flexGridIncludedTypes).EndInit();
    ((Control) this).ResumeLayout(false);
    ((Control) this).PerformLayout();
  }
}
